<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1.x,y,z分别是什么值
        var x = 1,
            y = z = 0;

        function add(n) {
            return n = n + 1
        }
        y = add(x)

        function add(n) {
            return n = n + 3;
        }
        z = add(x)
        // 1,4,4

        // 2. 
        function foo() {
            bar.apply(null, arguments)
        }
        function bar() {
            console.log(arguments)
        }
        foo(1, 2, 3, 4, 5)
        // [1, 2, 3, 4, 5]

        // 3.call和apply的作用：改变this指向，区别是传参列表不一样

    </script>

    <script>
        // 
        var name = 222;
        var a = {
            name: 111,
            say: function () {
                console.log(this.name)
            }
        }

        var fun = a.say;
        fun() //222
        a.say()  //111

        var b = {
            name: 333,
            say: function (fun) {
                fun()
            }
        }

        b.say(a.say) //222
        b.say = a.say;  //333



        // 
        var foo = 123;
        function print() {
            this.foo = 789;
            console.log(foo)
        }

        print()


        // 

        var bar = 123;
        function print() {
            bar.a = 'a'
            Object.prototype.b = 'b'
            return function inner() {
                console.log(bar.a)
                console.log(bar.b)
            }
        }
        print()()
    </script>
</body>

</html>